<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Project;
use App\Att;

class ProController extends Controller
{
    //
    public function getjie(){
    	return view('woyaojiekuan');
    }

    public function postjie(Request $req){
      $this->validate($req,[
          'age'=>'required|in:15,40,80',
          'money'=>'required|integer|between:0,20000000',
          'mobile'=>'required|regex:/^1[34578][0-9]{9}$/',
        ],
        [
          'in'=>'请选择:attribute',
          'between'=>':attribute的取值必须在:min和:max之间',
          'money.required'=>'1',
          'money.integer'=>'2',
          'money.between'=>'2'
        ]
        );
            $user = $req->user();
    	$pro = new Project();
    	$pro->age = $req->age;
    	$pro->money = $req->money*100;
    	$pro->mobile = $req->mobile;
    	$pro->uid = $user->uid;
    	$pro->name= $user->name;
    	$pro->status=0;

            $rs = $pro->save();

            var_dump($rs);

    }

    public function liebiao(){
        $pros = Project::where('status',0)->get();
        // $pros = [];
        return view('prolist',['pros'=>$pros]);
    }

    public function getshenhe($pid){
        $pro = Project::select('money')->find($pid);
        return view('shenhe',['pro' => $pro]);
    }

    public function postshenhe(request $req,$pid){
        //dd($req->input());
  //         "title" => "借钱看电影"
  // "realname" => "周哲阳"
  // "gender" => "1"
  // "marry" => "1"
  // "money" => "6000"
  // "salary" => "100"
  // "jobcity" => "阿拉斯加"
  // "hrange" => "12"
  // "rate" => "15"
  // "udesc" => "已欠债20亿,就是不还."
  // "status" => "1"
        $pro = Project::find($pid);
        $pro->title = $req->title;
        $pro->money = $req->money*100;
        $pro->hrange = $req->hrange;
        $pro->rate = $req->rate;
        $pro->status = $req->status;

        $rs0 = $pro->save();

        $att = new Att;
        $att->uid = $pro->uid;
        $att->pid = $pro->pid;
        $att->title = $req->title;
        $att->realname = $req->realname;
        $att->gender = $req->gender;
        $att->marry = $req->marry;
        $att->salary = $req->salary;
        $att->jobcity = $req->jobcity;
        $att->udesc = $req->udesc;

        $rs1 = $att->save();

        var_dump($rs0);
        var_dump($rs1);



    }

}
